package software_construction.chapter04.d1_fileio.demo2;

import software_construction.chapter04.d1_fileio.demo1.Student;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class FileReaderTest2 {
    public static void main(String[] args) {
        File file = new File("D:\\untitled\\src\\software_construction\\chapter04\\d1_fileio\\demo1\\student.txt");
        Scanner scanner=null;
        try {
            scanner = new Scanner(file);
            scanner.useDelimiter(",");
            List<Student> studentList = new ArrayList<>();
            while(scanner.hasNext()){
                String[] s= scanner.next().split(" ");
                Student student=new Student(Integer.parseInt(s[0]),s[1]);
                studentList.add(student);
            }
            System.out.println(studentList);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            scanner.close();
        }
    }
}
